#include <linux/mm.h>
#include <linux/tty.h>
#include <linux/page.h>
#include <linux/kernel.h>
#include <linux/string.h>
#include <linux/malloc.h>

extern char _end;

extern char empty_zero_page[PAGE_SIZE];
extern void kmalloc_init();

#define PARAM       empty_zero_page
#define EXT_MEM_K   (*(unsigned short *)(PARAM + 2))
#define SCREEN_INFO (*(struct screen_info *)(PARAM + 0))

extern void time_init(void);

static unsigned long memory_start = 0;
static unsigned long memory_end = 0;

struct screen_info screen_info;

extern void trap_init(void);

void start_kernel() {
    screen_info = SCREEN_INFO;
    memory_start = (unsigned long)&_end;
    memory_end = ((1 << 20) + (EXT_MEM_K << 10)) & PAGE_MASK;
    memory_end = __va(memory_end);
    memory_start = paging_init(memory_start, memory_end);
    trap_init();
    kmalloc_init();
    con_init();
    mem_init(memory_start, memory_end);
    memset(empty_zero_page, 0, PAGE_SIZE);
    time_init();

    char *p = (char *)kmalloc(16, GFP_KERNEL);
    p[0] = 'a';
    p[1] = 0;
    printk("str: %s\n", p);
    printk("addr: %p\n", p);
    kfree(p);
    printk("str: %s\n", p);
    printk("addr: %p\n", p);
}
